
/* GENERATED CODE:
 *  Any modifications you make are guaranteed
 *  to be deleted when this is regenerated.
 * Please edit "PROTOCOLS" inside this directory
 *
 * Names are all upper case because of "String" and "string."
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OWED.Network.Messages.General;
using OWED.Network.Messages;
using OWED.Network.Messages.Reply;


namespace OWED.Network.Messages.General
{
	public class Discussion: IProtocolItem 
	{
		List <CommentRef> my_Comments;
		int my_id;
		String my_docname;
		public Discussion (int id, String docname, List <CommentRef> Comments)
		{
			my_id = id;
			my_docname = docname;
			my_Comments = Comments;
		}
		public List <CommentRef> Comments { get { return my_Comments; } }
		public int id { get { return my_id; } }
		public String docname { get { return my_docname; } }


		public static new Discussion FromXml(XmlDocument xml)
		{
			int id = int.Parse(xml.SelectSingleNode("Discussion").Attributes.GetNamedItem("id").Value);
			String docname = xml.SelectSingleNode("Discussion").Attributes.GetNamedItem("docname").Value;
			XmlDocument doc;
			if (true) {
				XmlNodeList list_Comments = xml.SelectNodes("Discussion/CommentRef");
				List <CommentRef> Comments = new List <CommentRef>();
				foreach (XmlNode node in list_Comments) {
					doc = new XmlDocument();
					doc.AppendChild(doc.ImportNode(node, true));
					Comments.Add(CommentRef.FromXml(doc));
				}

				return new Discussion(id, docname, Comments);
			}
		}


		public override XmlDocument ToXml()		{
			XmlDocument doc = new XmlDocument();

			doc.AppendChild(doc.CreateElement("Discussion"));
			XmlAttribute attr;
			attr = doc.CreateAttribute("id");
			attr.Value = my_id.ToString();
			doc.FirstChild.Attributes.Append(attr);

			attr = doc.CreateAttribute("docname");
			attr.Value = my_docname;
			doc.FirstChild.Attributes.Append(attr);


			if (my_Comments != null) {
				XmlNode node;
				foreach (CommentRef item in my_Comments) {
					node = doc.ImportNode(item.ToXml().FirstChild, true);
					doc.FirstChild.AppendChild(node);
				}
			}

			return doc;
		}
	}
}
